package model

import (
	"mlgmd.com/hearsay/entities"
	"xorm.io/xorm"
)

type Report struct {
	entities.Report `xorm:"extends"`
	Creator         entities.User `xorm:"extends" json:"creator"`
	TargetUser      entities.User `xorm:"extends" json:"targetUser"`
	//TargetHearsay   entities.Hearsay `xorm:"extends" json:"targetHearsay"`
	//TargetReward    entities.Reward  `xorm:"extends" json:"targetReward"`
}

func (Report) Query(DB xorm.Interface) *xorm.Session {
	return DB.Table([]any{&entities.Report{}, "r"}).
		Join("INNER", []any{&entities.User{}, "c"}, "c.id=r.creator_id").
		Join("INNER", []any{&entities.User{}, "tu"}, "tu.id=r.target_user_id")
}

type ReportWithCreator struct {
	entities.Report `xorm:"extends"`
	Creator         entities.User `xorm:"extends" json:"creator"`
}

func (ReportWithCreator) Query(DB xorm.Interface) *xorm.Session {
	return DB.Table([]any{&entities.Report{}, "r"}).
		Join("INNER", []any{&entities.User{}, "c"}, "c.id=r.creator_id")
}

type ReportWithTargetUser struct {
	entities.Report `xorm:"extends"`
	TargetUser      entities.User `xorm:"extends" json:"targetUser"`
}

func (ReportWithTargetUser) Query(DB xorm.Interface) *xorm.Session {
	return DB.Table([]any{&entities.Report{}, "r"}).
		Join("INNER", []any{&entities.User{}, "tu"}, "tu.id=r.target_user_id")
}
